{% extends 'layout.html' %}
{% block css %}
    <style type="text/css">
        .pull-right.pagination-detail {
            display: none;
        }
    </style>
{% endblock %}
{% block content %}
    <div class="mobiledj-container">

        {% if search_group_row_list %}
            <div class="panel panel-default">
                <div class="panel-heading">
                    <i class="fa fa-filter" aria-hidden="true"></i> 快速筛选
                    <div class="fold-button pull-right">
                        <span class="open_panel" style="display: none;cursor: pointer;">展开</span>
                        <span class="close_panel" style="cursor: pointer;">收起</span>
                    </div>
                </div>
                <div class="panel-body fold-box">
                    <div class="search-group card card-body">
                        {% for row in search_group_row_list %}
                            <div class="row">
                                {% for obj in row %}
                                    {{ obj|safe }}
                                {% endfor %}
                            </div>
                        {% endfor %}
                    </div>
                </div>
            </div>
        {% endif %}

        {% if search_list %}
            <div style="float: right;margin: 5px 0;">
                <form method="GET" class="form-inline">
                    <div class="form-group">
                        <input class="form-control" type="text" name="q" value="{{ search_value }}" placeholder="关键字搜索">
                        <button class="btn btn-primary" type="submit">
                            <i class="fa fa-search" aria-hidden="true"></i>
                        </button>
                    </div>
                </form>
            </div>
        {% endif %}

        <form method="post">
            {% csrf_token %}

            {% if action_dict %}
                <div style="float: left;margin: 5px 10px 5px 0;">
                    <div class="form-inline">
                        <div class="form-group">
                            <select class="form-control" name="action">
                                <option value="">请选择操作</option>
                                {% for func_name,func_text in action_dict.items %}
                                    <option value="{{ func_name }}">{{ func_text }}</option>
                                {% endfor %}
                            </select>
                            <input class="btn btn-primary" type="submit" value="执行"/>
                        </div>
                    </div>
                </div>
            {% endif %}

            {% if add_btn %}
                <div style="margin: 5px 0;float: left">
                    {{ add_btn|safe }}
                </div>
            {% endif %}

            <table class="table table-bordered table-hover table-striped">
                <thead class="root">
                <tr>
                    <th>序号</th>
                    {% for item in header_list %}
                        <th>{{ item }}</th>
                    {% endfor %}
                </tr>
                </thead>
                <tbody>
                {% for row in body_list %}
                    <tr>
                        <td>{{ forloop.counter }}</td>
                        {% for ele in row %}
                            <td>{{ ele }}</td>
                        {% endfor %}
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        </form>

        <nav class="row" style="margin: 0 0 0 10px;">
            <ul class="col-md-10 pagination">
                {{ pager.page_html|safe }}

                <div class="form-inline" style="margin: 0 0 0 10px;">
                    <span style="color: #337ab7;padding: 6px 12px;">共{{ pager.pager_count }}页，总计{{ pager.all_count }}条记录,每页显示</span>
                    <select class="form-control" id="ps" onchange="changePageSize(this)">
                        <option value=10>10</option>
                        <option value=30>30</option>
                        <option value=60>60</option>
                        <option value=100>100</option>
                        <option value=200>200</option>
                        <option value=300>300</option>
                    </select>
                    <span style="color: #337ab7">几条记录</span>
                </div>
            </ul>
        </nav>

    </div>

{% endblock %}
{% block js %}
    <script type="text/javascript">
        $(function () {
            $('.check-all').change(function () {
                $(this).parents('.root').next().find(':checkbox').prop('checked', $(this).prop('checked'));
            })
            var v = $.cookie('per_page_count');
            if (v == undefined) {
                $('#ps').val(10);
            } else {
                $('#ps').val(v)
            }
        });

        function changePageSize(ths) {
            var v = $(ths).val();
            console.log(v);
            $.cookie('per_page_count', v);
            location.reload()
        }

        $(function () {
            $(".fold-button").click(function () {
                $(".fold-box").slideToggle("normal");
                $(".open_panel").toggle();
                $(".close_panel").toggle();
            });
        });
    </script>
{% endblock %}